<?session_start();?>
	<?php require_once 'xhtmlHeader.php';?>
	<script type="text/javascript" src="lib/jquery.min.js"></script> 
	<script type="text/javascript" src="lib/jquery.pagination.js"></script>
	
	<script type="text/javascript">
      FB.init({
        appId  : '148131101921752',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : false  // parse XFBML
      });
	</script>
	
	
<script type="text/javascript"> 
	
	// This is a very simple demo that shows how a range of elements can
	// be paginated.
	// The elements that will be displayed are in a hidden DIV and are
	// cloned for display. The elements are static, there are no Ajax 
	// calls involved.

	/**
	 * Callback function that displays the content.
	 *
	 * Gets called every time the user clicks on a pagination link.
	 *
	 * @param {int} page_index New Page index
	 * @param {jQuery} jq the container with the pagination links as a jQuery object
	 */
	function pageselectCallback(page_index, jq){
		//var new_content = jQuery('#oculto div.elementores:eq('+page_index+')').clone();
		//$('#Searchresult').empty().append(new_content);
		///return false;
		var numElem=4;
		var content = jq;
		//$('#Searchresult').empty().append(new_content);
		//return false;
		$('#Searchresult').empty();
		//alert(page_index);
		for(var i=page_index*numElem;i<(page_index*numElem)+numElem;i++) {
            //$('#Searchresult').append(content[i]);
			//$('#Searchresult').append(content[i]);
			jQuery('#oculto div.elementores:eq('+i+')').clone().appendTo('#Searchresult');
        }
        return false;
	}
   
	/** 
	 * Initialisation function for pagination
	 */
	function initPagination() {
		// count entries inside the hidden content
		var num_entries = jQuery('#oculto div.elementores').length;
		// Create content inside pagination element
		$("#Pagination").pagination(num_entries, {
			callback: pageselectCallback,
			items_per_page:4 // Show only one item per page
		});
		pageselectCallback(0, jQuery('#oculto div.elementores'));
	 }
	
</script>


	
	
	
	<script>
     function interruptor(parte) { 
      /*parrafo = document.getElementById(parte); 
      switch(parrafo.style.display) {  
         case "inline"   :  
         case ""         :   parrafo.style.display = "none";  
                        break; 
         case "none"      :    parrafo.style.display = "inline";  
                        break; 
      }
	  switch(parrafo.style.visibility) {  
         case "visible"   :  
         case ""         :   parrafo.style.display = "hidden";  
                        break; 
         case "hidden"      :    parrafo.style.display = "visible";  
                        break; 
      }*/
	  /*$('div[id^="cine_"]'.css("display","inline");
	  $(".muestrame").attr("class","ocultame");
	  $(parte).attr("class","muestrame");*/
	  $("div[id^='cine_']").css("display","none");
	  $(parte).css("display","inline");
	  //FB.Canvas.setSize( );
   }
   
   function oculta(){ 
$("div[id^='cine_']").css("display","none");
	 
   } 
    </script>




 	<body>
 	<?php  //require 'resize2.js';
			//require 'resizeTamFijo.js';?>
	<div id="cuerpo">
	 <?php require 'config_bbdd.php';?>
	 <?php require_once 'cabecera.php';?>
	 <?php require_once 'muestraCine.php';?>
	 
		<div id="contenido">
		<?php //$user=1;
				//$_SESSION["idUser"] = $user;
				//if (!isset($_SESSION["nombreUser"]))
				//		require_once 'sacaVariablesSesion.php';

				if (!isset($_SESSION["idUser"])){
					require_once 'vars.php';
				}
				
				if (!isset($_SESSION["provinciaUser"])){
						$_SESSION['msgError']="Debes introducir tu provincia para poder ver los cines de tu ciudad.";
	 					header ("Location: configuracion.php");
				}
						?>

			<h1>Cines</h1>
			<p>A continuación puedes ver todos los cines de tu provincia disponibles en
			nuestra base de datos.</p>
			
			<?php 
			if (isset($_SESSION['provinciaUser'])){
				if (! @mysql_select_db("usersFB",$myconn)){
						exit();
					}
					
					$sql = "SELECT ID, Nombre FROM ssii.ciudad WHERE IDProvincia ='" .$_SESSION['provinciaUser']. "';";
					$result = mysql_query($sql, $myconn);

			?>
				<form ACTION="cinesDeProvincia.php" METHOD="post">
				<p>Elige una zona de tu provincia</p>
					<select name="zonas" onchange="prueba()">
						<option value="Todas">Todas</option>
						<?php
						while($row = mysql_fetch_array($result)){
							echo "<option value=\"".utf8_encode($row['ID'])."\">".utf8_encode($row['Nombre'])."</option> \n";
						}
						?>
					</select>
					<input type="submit" value="Ir">
					<br />
					
				</form>
			<?php 
			} 
			?>
			<div id="Pagination"></div>
			<div id="Searchresult" style="clear: left"> 
				Cargando los cines
			</div> 
			<?php
			 //Si no se puede conectar a la BBDD 
				if (! @mysql_select_db("usersFB",$myconn)){
					echo "<p>Error al conectar a la BBDD.</p>";
					exit();
				}
				
				//Saco las películas de la provincia. Así mejor que con subconsultas.
				if ( (isset($_POST['zonas'])) && ($_POST['zonas']!="Todas") ){
				$sql = "SELECT c.* FROM ssii.CINE c
					WHERE c.IDCiudad ='" .$_POST['zonas']. "';";
				}
				else{				
				$sql = "SELECT c.* FROM ssii.CINE c
					WHERE c.IDProvincia ='" .$_SESSION['provinciaUser']. "';";
				}
				$result = mysql_query($sql, $myconn);
				//Las muestro formateadas
				echo "<div id=\"oculto\" style=\"display:none;\">";
				while($row = mysql_fetch_array($result)){
					echo "<div class=\"elementores\">";
					//--------------------------------------------------
					muestraCine($row,$myconn,false);
					echo "</div>";//class="elementores"
					echo "\n";
					
				}//while
				echo "</div>";//id="oculto"
			?> 
		</div>
		<script>//$(".ocultame").css("display","none");
		$("div[id^='cine_']").css("display","none");
		</script>
		
		<script type="text/javascript"> 
			initPagination();
		</script> 
		
		
		
		
		<?php require_once 'columnaDerecha.php';?>
		<br />
		<br />
		<br />
		<?php require_once 'pie.php';?>
		
		<script type="text/javascript"> 
			FB.Canvas.setSize( );
		</script> 
	</div>	
 	</body>
</html>